<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>show image</title>
<%@ page import="com.test.getfile.*" %>
<link rel="stylesheet" type="text/css" href="css/test.css">
<script type="text/javascript">
var imgIndex = 0;
var xmlHttp;

function getNextImagePath()
{
	var imgtotal = document.getElementById("imgtotalnum").value;
	if(imgIndex >= imgtotal-1)
	{
		alert("已经是最后一张图片");
		return;
	}else
	{
		imgIndex++;
	}
	document.getElementById("imagePath").src="image_svr?imgnum=" + imgIndex;
	/*
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlHttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	content = "imgnum="+encodeURIComponent(imgIndex.toString());
	xmlHttp.open("POST", "image_svr", false);
	xmlHttp.onreadystatechange = callback;
	xmlHttp.setRequestHeader("Content-Length",content.length);
	xmlHttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
	xmlHttp.send(null);
	*/
}

function getPreImagePath()
{
	if(imgIndex <= 0)
	{
		alert("已经是第一张图片");
		return;
	}else
	{
		imgIndex--;
	}
	document.getElementById("imagePath").src="image_svr?imgnum=" + imgIndex;
/*	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlHttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	content = "imgnum="+encodeURIComponent(imgIndex.toString());
	xmlHttp.open("POST", "image_svr", false);
	xmlHttp.onreadystatechange = callback;
	xmlHttp.setRequestHeader("Content-Length",content.length);
	xmlHttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
	xmlHttp.send(content);
	*/
}

function callback()
{
	if(xmlHttp.readyState == 4) 
	{
	   if(xmlHttp.status == 200) 
	   {
	       document.getElementById("imagePath").src="image_svr?imgnum=" + imgIndex;
	   }
	}
}

</script>

</head>
<body>
<%! String currentUser = null; %>
<%
//判断是否已经有用户登录
	currentUser = (String)session.getAttribute("currentUser");
	if(null != currentUser)
	{
		out.print("<p id='welcomeInfo'> 当前登录用户："+currentUser+" <a href='/ImageTest/test.jsp'>退出当前用户</a></p>");
	}
	
%>

<%
	//限制未登录用户不能查看本页面内容
	session = request.getSession();
	String hasLogin = (String)session.getAttribute("hasLogin");
	if(!"hasLogined".equals(hasLogin))
	{
		request.setAttribute("hasLogin", "请先登录，才可以浏览图片!");
		ServletContext sc = getServletContext();
        RequestDispatcher rd = null;
        rd = sc.getRequestDispatcher("/login.jsp");//
        rd.forward(request, response);
		return;
	}
%>

<%! int nTotalFileNum = 0; %>
<%
	TestFile tf = new TestFile();
	tf.GetFilePath("D:/1");
	nTotalFileNum = tf.filePathList.size();
	//System.out.println(nTotalFileNum);
%>

<div id="header"></div>

<ul id="nav">
<li><a href="/ImageTest/index.jsp">首页</a></li>
<li><a href="/ImageTest/viewImage.jsp">看图片</a></li>
<li><a href="/ImageTest/upload_file.jsp">上传图片</a></li>
<li><a href="/ImageTest/login.jsp">登录</a></li>
<li><a href="/ImageTest/regist.jsp">注册用户</a></li>
<li><a href="/ImageTest/administor.jsp">管理员</a></li>
</ul>

<div id="img">
<img id="imagePath" src="image_svr"/>
<input type="button" id="pre" value="prev" onClick="getPreImagePath()"/>
<input type="button" id="next" value="next" onClick="getNextImagePath()"/> 
<input type="hidden" id="imgtotalnum" value="<%= nTotalFileNum%>">  
</div>


</body>
</html>